package com.ehotting.mqbd.api.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.ehotting.eaf.core.text.UUID;
import com.ehotting.eaf.core.utils.DateUtils;
import com.ehotting.mqbd.api.MqDataStateConstants;
import com.ehotting.mqbd.api.enums.*;
import org.springframework.util.Assert;

import java.util.Date;

public abstract class MQBaseData<R , A > implements MQDataAble {

    protected String serial = UUID.getUUID();
    protected String time = DateUtils.getDateTimeString(new Date());
    protected String module;
    protected String msg;
    protected String agentId;
    protected String consumerHost;
    protected String localHost;
    protected String direction;
    protected TopicEnum topic;
    protected String action ;
    /**求解器节点IP**/
    protected String solverIp;
    protected String state = MqDataStateConstants.SUCCESS;
    protected ProtocolTypeEnum protocolType = ProtocolTypeEnum.HTTP;

    protected Boolean syncExecute = true;
    protected String authorization;

    @JSONField(serialize = false)
    protected Boolean logRequest = true;
    @JSONField(serialize = false)
    protected Boolean logResponse = true;
    @JSONField(serialize = false)
    protected Boolean sendRequest = true;
    @JSONField(serialize = false)
    protected Boolean sendResponse = true;

    protected Class<?> requestClazz;

    protected Class<?> responseClazz;

    protected Class<?> clazz;

    /***
     * 请求大报文的存储索引，可以Redis的key,也可以是文件路径
     */
    protected String requestIndex;
    /***
     * 响应大报文的存储索引，可以Redis的key,也可以是文件路径
     */
    protected String responseIndex;

    protected SendTypeEnum[] sendType = {SendTypeEnum.SEND_BODY};

    protected R request;

    protected A response;


    protected String requestString;
    protected String responseString;

    protected boolean isAutoTopic = true;

    protected SolveStepEnum solveStep = SolveStepEnum.ONE;

    protected String msgId;

    protected MQDataPushModelEnum pushModel;

    /***
     * 求解报文自动websocket push
     */
    protected boolean isAutoPush = true;



    public MQBaseData(){
    }

    public MQBaseData(String action){
        this.action = action;
    }
    public MQBaseData(String action,String serial){
        this.action = action;
        this.serial = serial;
    }

    public MQBaseData(TopicEnum topic, String consumerHost, String localHost, String agentId, String module, String msg){
        Assert.notNull(topic,"topic is null");

        this.setTopic(topic);
        this.setDirection(DirectionEnum.REQUEST.getCode());
        this.setAgentId(agentId);
        this.setConsumerHost(consumerHost);
        this.setLocalHost(localHost);
        this.setModule(module);
        this.setMsg(msg);

    }


    @Override
    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    @Override
    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }



    public String getAgentId() {
        return agentId;
    }

    public void setAgentId(String agentId) {
        this.agentId = agentId;
    }

    @Override
    public String getConsumerHost() {
        return consumerHost;
    }

    public void setConsumerHost(String consumerHost) {
        this.consumerHost = consumerHost;
    }

    @Override
    public Boolean isSync() {
        return syncExecute;
    }

    @Override
    public void setSync(Boolean syncExecute) {
        this.syncExecute = syncExecute;
    }

    @Override
    public String getDirection() {
        return direction;
    }

    @Override
    public String getTime() {
        return time;
    }

    @Override
    public String getSolverIp() {
        return solverIp;
    }

    @Override
    public void setSolverIp(String solverIp) {
        this.solverIp = solverIp;
    }

    public void setDirection(String direction) {
        this.direction = direction;
    }

    @Override
    public ProtocolTypeEnum getProtocolType() {
        return protocolType;
    }

    public void setProtocolType(ProtocolTypeEnum protocolType) {
        this.protocolType = protocolType;
    }

    @Override
    public String getLocalHost() {
        return localHost;
    }

    public void setLocalHost(String localHost) {
        this.localHost = localHost;
    }

    @Override
    public TopicEnum getTopic() {
        return topic;
    }

    public void setTopic(TopicEnum topic) {
        this.topic = topic;
    }

    @Override
    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }


    @Override
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }



    public void setTime(String time) {
        this.time = time;
    }



    public String getAuthorization() {
        return authorization;
    }

    public void setAuthorization(String authorization) {
        this.authorization = authorization;
    }

    public Boolean isLogRequest() {
        return logRequest;
    }

    public void setLogRequest(Boolean logRequest) {
        this.logRequest = logRequest;
    }

    public Boolean isLogResponse() {
        return logResponse;
    }

    public void setLogResponse(Boolean logResponse) {
        this.logResponse = logResponse;
    }

    public Boolean isSendRequest() {
        return sendRequest;
    }

    public void setSendRequest(Boolean sendRequest) {
        this.sendRequest = sendRequest;
    }

    public Boolean isSendResponse() {
        return sendResponse;
    }

    public void setSendResponse(Boolean sendResponse) {
        this.sendResponse = sendResponse;
    }

    public Class getRequestClazz() {

        return this.requestClazz;
    }

    public Class getResponseClazz() {
        return this.responseClazz;
    }

    public void setRequestClazz(Class requestClazz) {
        this.requestClazz = requestClazz;
    }

    public void setResponseClazz(Class responseClazz) {
        this.responseClazz = responseClazz;
    }


    public String getRequestIndex() {
        return requestIndex;
    }

    public void setRequestIndex(String requestIndex) {
        this.requestIndex = requestIndex;
    }

    public String getResponseIndex() {
        return responseIndex;
    }

    public void setResponseIndex(String responseIndex) {
        this.responseIndex = responseIndex;
    }

    @Override
    public SendTypeEnum[] getSendType() {
        return sendType;
    }

    @Override
    public void setSendType(SendTypeEnum[] sendType) {
        this.sendType = sendType;
    }

    @Override
    public R getRequest() {
        return request;
    }


    @Override
    public A getResponse() {
        return response;
    }

    public abstract void setRequest(R request);

    public abstract void setResponse(A request);

    @Override
    public Class<?> getClazz() {
        return clazz;
    }


    public void loadClazz() {
        this.clazz = this.getClass();
    }

    public String getRequestString() {
        return requestString;
    }

    public void setRequestString(String requestString) {
        this.requestString = requestString;
    }

    public String getResponseString() {
        return responseString;
    }

    public void setResponseString(String responseString) {
        this.responseString = responseString;
    }

    public boolean isAutoTopic() {
        return isAutoTopic;
    }

    public void setAutoTopic(boolean autoTopic) {
        isAutoTopic = autoTopic;
    }

    @Override
    public SolveStepEnum getSolveStep() {
        return solveStep;
    }

    @Override
    public void setSolveStep(SolveStepEnum solveStep) {
        this.solveStep = solveStep;
    }

    @Override
    public String getMsgId() {
        return msgId;
    }

    @Override
    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }


    public MQDataPushModelEnum getPushModel() {
        return pushModel;
    }

    public void setPushModel(MQDataPushModelEnum pushModel) {
        this.pushModel = pushModel;
    }

    public boolean isAutoPush() {
        return isAutoPush;
    }

    public void setAutoPush(boolean autoPush) {
        isAutoPush = autoPush;
    }
}
